﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HRRequest_Form.aspx.cs"
    Inherits="Trig_AMJ_HR_Forms.Layouts.Trig_AMJ_HR_Forms.HRRequest_Form" DynamicMasterPageFile="~masterurl/default.master" %>

<%@ Register TagPrefix="trig" TagName="HRComments" Src="~/_controltemplates/Trig_AMJ_AMG_Forms/TrigAMJFormsComments/TrigAMJFormsCommentsUserControl.ascx" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <link rel="Stylesheet" type="text/css" href="/_layouts/1033/STYLES/Themable/FORMS.CSS" />
    <link rel="Stylesheet" type="text/css" href="/Style Library/Al Majed/CSS/Trig_HR.css" />
    <style type="text/css">
        #s4-leftpanel
        {
            display: none;
        }
        .s4-ca
        {
            margin-left: 0px;
        }
        .ms-validations
        {
            color: Red;
        }
        .style2
        {
            width: 373px;
        }
        .style3
        {
            width: 366px;
        }
        body, td, th
        {
            font-size: 8pt;
            font-family: Verdana, Arial, sans-serif;
        }
    </style>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <asp:Panel ID="pnlFullForm" runat="server" CssClass="pnlAMFform">
        <table cellpadding="0" cellspacing="0" class="tbl-main" width="800px">
            <tr>
                <td colspan="4" class="formtitle">
                    HR Request Form
                </td>
            </tr>
            <tr>
                <td colspan="4" class="Note-td">
                    <asp:Label ID="lblnote1" runat="server" Text="Some notes will be come here!!!" CssClass="Notes-msg"></asp:Label>
                </td>
            </tr>
            <tr>
                <td width="150px">
                    Reference No :
                </td>
                <td class="tdCell">
                    <asp:Label ID="lblHRReqNo" runat="server" Text="Reference number will be generated upon save"
                        Font-Bold="True" Font-Size="XX-Small" CssClass="ms-long ms-spellcheck-true" ForeColor="Red"
                        Width="250px"></asp:Label>
                </td>
                <td width="150px">
                    Date of filling :
                </td>
                <td width="250px">
                    <SharePoint:DateTimeControl ID="dtpDate" runat="server" DateOnly="true" IsRequiredField="true"
                        LocaleId="2057" Enabled="false" ErrorMessage="Please specify the date" />
                </td>
            </tr>
            <tr>
                <td width="150px">
                    Request Type : <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td width="250px">
                    <asp:DropDownList runat="server" ID="ddRequestType" AutoPostBack="true" OnSelectedIndexChanged="ddRequestType_SelectedIndexChanged">
                    </asp:DropDownList>
                </td>
            </tr>
            <asp:UpdatePanel runat="server" ID="uptReqEmp">
                <ContentTemplate>
                    <asp:Panel ID="pnlReqEmpInf" runat="server" Visible="false">
                        <tr>
                            <td class="tdHeadingTextLeftAlign" colspan="4">
                                Requested Employee Information
                            </td>
                        </tr>
                        <tr>
                            <td width="150px">
                                Name :<span title="This is a required field." class="ms-validations"><strong>*</strong></span>
                            </td>
                            <td>
                                <SharePoint:PeopleEditor ID="pplReqUser" runat="server" MultiSelect="false" AutoPostBack="true"
                                    SelectionSet="User" Width="250px" />
                                    <asp:HiddenField runat="server" ID="hndUser" />
                                <asp:TextBox ID="txtReqUser" runat="server" ReadOnly="true" Width="250px" Visible="false"
                                    Enabled="false"></asp:TextBox>
                            </td>
                            <td width="150px">
                                Employee ID :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqEmpId" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td width="150px">
                                Division :
                            </td>
                            <td class="tdCell">
                                <asp:TextBox ID="txtReqDivision" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                            </td>
                            <td width="150px">
                                Designation :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqDesignation" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Nationality :
                            </td>
                            <td class="tdCell">
                                <asp:TextBox ID="txtNationality" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                            </td>
                            <td width="150px">
                                Sponsor Number : <span title="This is a required field." class="ms-validations"><strong>
                                    *</strong></span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtSponsorNo" runat="server" Width="250px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td width="150px">
                                Branch of sponsorship : <span title="This is a required field." class="ms-validations">
                                    <strong>*</strong></span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtSponsorBranch" runat="server" Width="250px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td width="150px">
                                Travel Date :
                            </td>
                            <td width="250px">
                                <SharePoint:DateTimeControl ID="dtTravelDate" runat="server" DateOnly="true" IsRequiredField="true"
                                    Enabled="false" LocaleId="2057" />
                            </td>
                            <td width="150px">
                                Return Date :
                            </td>
                            <td width="250px">
                                <SharePoint:DateTimeControl ID="dtReturnDate" runat="server" DateOnly="true" IsRequiredField="true"
                                    Enabled="false" LocaleId="2057" />
                            </td>
                        </tr>
                        <tr>
                            <td width="150px">
                                Leave Reference No :
                            </td>
                            <td>
                                <asp:TextBox ID="txtLeaveRefNo" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                            </td>
                            <td width="150px">
                                Leave Request Date :
                            </td>
                            <td width="250px">
                                <SharePoint:DateTimeControl ID="dtLeaveReqDate" runat="server" DateOnly="true" LocaleId="2057" Enabled="false" />
                            </td>
                        </tr>
                    </asp:Panel>
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="ddRequestType" />
                </Triggers>
            </asp:UpdatePanel>
            <tr>
                <td colspan="4" class="tdHeadingTextLeftAlign">
                    Comments / Workflow Area
                </td>
            </tr>
            <tr>
                <td colspan="4" style="padding: 10px;">
                    <trig:HRComments ID="HRComments" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <table width="100%" cellpadding="0" cellspacing="0" class="Section-Approver">
                        <asp:Panel ID="pnlCommentArea" runat="server" class="Section-Approver">
                            <tr>
                                <td colspan="4" class="AppHeading">
                                    <strong>Comments</strong><span class="ms-validations" title="This is a required field."><strong>
                                        *</strong></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="tdCell">
                                    <asp:Image ID="ImgUser" runat="server" Height="50px" Width="50px" />
                                    <br />
                                    <asp:Label ID="LblCommentsUserName" runat="server" Font-Bold="True" Font-Size="XX-Small"
                                        ForeColor="#003399" Text=""></asp:Label>
                                </td>
                                <td colspan="3" class="tdCell">
                                    <asp:TextBox ID="TxtComments" runat="server" TextMode="MultiLine" Width="600px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr id="upAtt" runat="server">
                                <td class="tdCell">
                                    Upload Attachment
                                </td>
                                <td colspan="3" class="tdCell">
                                    <asp:FileUpload ID="upfile" runat="server" CssClass="ms-fileinput" Width="250px" />
                                </td>
                            </tr>
                        </asp:Panel>
                        <asp:Panel ID="pnlForward" runat="server" Visible="false">
                            <tr>
                                <td colspan="4" style="text-align: left; background-color: #121e66; color: #ffffff;
                                    font-weight: bold; padding: 10px;">
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbSendBack" runat="server" Text="Send Back" GroupName="Users"
                                                            AutoPostBack="true" onclick="javascript:fnSendBackUsers(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbSendBack" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbForwardOthers" runat="server" Text="Forward to other user"
                                                            AutoPostBack="true" GroupName="Users" onclick="javascript:fnForwardUsers(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbForwardOthers" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbForward" runat="server" Text="Forward" GroupName="Users"
                                                            AutoPostBack="true" onclick="javascript:fnForword(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbForward" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
                                                <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                                                    <ContentTemplate>
                                                        <asp:Label ID="lblWFStaticUser" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow"></asp:Label>
                                                        <asp:Label ID="lblSendBacktoUser" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow" Visible="false"></asp:Label>
                                                        <asp:Label ID="lblsendBackUserValue" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow"></asp:Label>
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr style="padding: 10px; display: none" id="trotherUsers">
                                <td style="padding: 10px; font-weight: bold; color: #121e66;" width="130px">
                                    User Name :
                                </td>
                                <td style="padding: 10px;" colspan="3">
                                    <asp:Label ID="lblCNTSectionMsg" runat="server" Text=""></asp:Label>
                                    <SharePoint:PeopleEditor ID="pplcnt" runat="server" MultiSelect="false" AllowEmpty="false"
                                        Width="250px" ForeColor="Red" AutoPostBack="false" />
                                </td>
                            </tr>
                        </asp:Panel>
                        <asp:Panel runat="server" ID="btnCntrls">
                            <tr>
                                <td colspan="4">
                                    <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                                        <ContentTemplate>
                                            <asp:Label ID="lblError" runat="server" CssClass="error-msg" Text=""></asp:Label>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" class="tblButtons" style="padding-top: 5px;">
                                    <asp:HiddenField runat="server" ID="ckSubmit" Value="false" />
                                    <asp:Button ID="btnSubmit" runat="server" CssClass="btn-Submit" Text="Submit" OnClick="btnSubmit_Click"
                                        OnClientClick="javascript:return fnValidation();" />
                                    <asp:Button ID="btnApprove" runat="server" CssClass="btn-Approver" Text="Approve"
                                        OnClick="btnApprove_Click" OnClientClick="javascript:return fnValidationApprove();"
                                        Visible="false" />
                                    <asp:Button ID="btnReject" runat="server" CssClass="btn-Reject" Text="Reject" OnClick="btnReject_Click"
                                        Visible="false" OnClientClick="javascript:return fnValidationApprove();" />
                                    <input id="btnCancel" class="btn-Cancel" type="button" value="Close" accesskey="C"
                                        onclick="window.parent.history.back()"
                                        runat="server" />
                                </td>
                            </tr>
                        </asp:Panel>
                    </table>
                </td>
            </tr>
            <asp:Panel ID="pnlView" runat="server" Visible="false">
                <tr>
                    <td colspan="4" style="text-align: center;">
                        <input id="btnViewClose" class="btn-Cancel" type="button" onclick="window.parent.history.back()"
                            value="Close" accesskey="C" />
                    </td>
                </tr>
            </asp:Panel>
        </table>
    </asp:Panel>
    <asp:Panel ID="pnlAccessDenied" runat="server" Visible="false" CssClass="pnlAMFform">
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td style="text-align: center;">
                    <asp:Label ID="lblAccessDeniedMsg" runat="server" Text="" Font-Size="Medium" ForeColor="Red"
                        Font-Bold="True" Visible="false"></asp:Label>
                    <asp:Label ID="lblUserNotvailable" runat="server" Text="" Font-Size="Medium" ForeColor="Red"
                        Font-Bold="True" Visible="false"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px;">
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/_layouts/1033/IMAGES/IRForm/AccessDeniedImage.png" />
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px">
                    <input id="butonclose" class="ms-ButtonHeightWidth" type="button" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancel clicked'); return false;"
                        value="Close" accesskey="C" />
                </td>
            </tr>
        </table>
    </asp:Panel>

     <asp:Panel ID="pnlAlert" runat="server">
    </asp:Panel>

    <script language="javascript" type="text/javascript">

        function fnValidationApprove() {

            debugger;
            document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
            Trim(document.getElementById('<%= TxtComments.ClientID  %>'));

            var rval = true;
            var ErrorMsg = "";
            var objFocus;

            if (document.getElementById('<%= TxtComments.ClientID  %>').value == "") {
                ErrorMsg = "Fields marked with (*) cannot be left blank";
                objFocus = document.getElementById('<%= TxtComments.ClientID  %>');
                rval = false;
            }

            if (rval == false) {
                document.getElementById('<%= lblError.ClientID  %>').style.display = "block";
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = ErrorMsg;
                objFocus.focus();
            }

            else {
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
                document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
            }
            return rval;
        }
    
    </script>



    <script language="javascript" type="text/javascript">

        document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
        document.getElementById('<%= lblError.ClientID  %>').style.display = "none";


        function Trim(TrimString) {
            var tempObj;
            if (TrimString) { tempObj = TrimString; TrimString = tempObj.value; }
            if (TrimString == "undefined" || TrimString == null) return null;
            if (TrimString.length == 0) TrimString = "";
            else {
                var Lcont = 0, TempStrArray = TrimString.split(" "), Rcont = TempStrArray.length - 1;
                while (TempStrArray[Lcont] == "") Lcont++; while (TempStrArray[Rcont] == "") Rcont--;
                if (Rcont < Lcont) TrimString = ""; else
                    for (TrimString = TempStrArray[Lcont], Lcont++; Lcont <= Rcont; Lcont++) TrimString += " " + TempStrArray[Lcont];
                var re = /\'|/g;
                TrimString = TrimString.replace(re, "");
            }
            if (tempObj && TrimString != "undefined" && TrimString != null)
            { tempObj.value = TrimString; return tempObj }
            else return TrimString;
        }

        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.search);
            if (results == null)
                return "";
            else
                return decodeURIComponent(results[1].replace(/\+/g, " "));
        }


        function fnValidation() {
            var rval = true;
            debugger;
            var querystringval = getParameterByName('Mode');
            var ErrorMsg = "";
            var objFocus;
            var reqType;


            if (querystringval == "New") {

                Trim(document.getElementById('<%= TxtComments.ClientID  %>'));
                Trim(document.getElementById('<%= ddRequestType.ClientID  %>'));
                Trim(document.getElementById('<%= ckSubmit.ClientID  %>'));

                if (document.getElementById('<%= TxtComments.ClientID  %>').value == "") {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = document.getElementById('<%= TxtComments.ClientID  %>');
                    rval = false;
                }

                var objDDl;

                objDDl = document.getElementById('<%=ddRequestType.ClientID%>');
                if (objDDl.value == "") {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = document.getElementById('<%= ddRequestType.ClientID  %>');
                    rval = false;

                }
                else {
                    if (objDDl.options[objDDl.selectedIndex].value == "Select") {
                        ErrorMsg = "Fields marked with (*) cannot be left blank";
                        objFocus = document.getElementById('<%= ddRequestType.ClientID  %>');
                        rval = false;
                    }

                    else {
                        reqType = objDDl.options[objDDl.selectedIndex].value;
                        if (reqType == "Exit Permit for Leave") {

                            Trim(document.getElementById('<%= pplReqUser.ClientID  %>'));
                            Trim(document.getElementById('<%= txtSponsorNo.ClientID  %>'));
                            Trim(document.getElementById('<%= txtSponsorBranch.ClientID  %>'));

                            if (document.getElementById('<%= pplReqUser.ClientID  %>').value == "") {
                                ErrorMsg = "Fields marked with (*) cannot be left blank";
                                objFocus = document.getElementById('<%= pplReqUser.ClientID  %>');
                                rval = false;
                            }
                            else if (document.getElementById('<%= txtSponsorNo.ClientID  %>').value == "") {
                                ErrorMsg = "Fields marked with (*) cannot be left blank";
                                objFocus = document.getElementById('<%= txtSponsorNo.ClientID  %>');
                                rval = false;
                            }
                            else if (document.getElementById('<%= txtSponsorBranch.ClientID  %>').value == "") {
                                ErrorMsg = "Fields marked with (*) cannot be left blank";
                                objFocus = document.getElementById('<%= txtSponsorBranch.ClientID  %>');
                                rval = false;
                            }
                        }
                        else {

                        }
                    }
                }

                if (rval == false) {
                    document.getElementById('<%= lblError.ClientID  %>').style.display = "block";
                    document.getElementById('<%= lblError.ClientID  %>').innerHTML = ErrorMsg;
                    objFocus.focus();
                }
                else {
                    document.getElementById('<%= ckSubmit.ClientID  %>').value = "True";
                    document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
                    document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
                }
                return rval;
            }

        }


        function cntrlsForExit() {
            debugger;
            var e = document.getElementById('<%= ddRequestType %>')
            var reqType = e.options[e.selectedIndex].value;
            if (reqType == "Exit Permit for Leave")
                document.getElementById('<%= pnlReqEmpInf %>').style.visibility = 'visible';
            else
                document.getElementById('<%= pnlReqEmpInf %>').style.visibility = 'none';

        }
    </script>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    HR Request Form
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    HR Request Form
</asp:Content>
